import { GTable } from 'geminis-react';
import { Button } from 'antd';
import React, { useRef } from 'react';

export default () => {
  const table = useRef<any>();

  const tableSchema = {
    headerTitle: '待处理',
    data: {
      url: '/api/workflow/task/my',
    },
    action: {
      row: {
        render: (record: any) => [
          <Button
            type="link"
            onClick={() => {
              const openedWindow = window.open(
                '/center/workflow/todo?' +
                'processDefinitionName=' +
                record.processDefinitionName +
                '&taskDefinitionName=' +
                record.taskDefinitionName +
                '&processInstanceId=' +
                record.processInstanceId +
                '&taskId=' +
                record.id +
                '&formUrl=' +
                btoa(record.formKey));

              const loop = setInterval(() => {
                if (openedWindow != null && openedWindow.closed) {
                  table.current.loadData();
                  clearInterval(loop);
                }
              }, 1000);
            }}
          >
            处理
          </Button>,
        ],
      },
    },
  };

  return (
    <GTable
      ref={table}
      schema={tableSchema}
      schemaPath="/workflow-pc/schema/work/todo.json"
    />
  );
};
